package com.panfeng.xcloud.common.core.utils;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

import java.util.Locale;

public class ResourceMessageUtil {

    private static ReloadableResourceBundleMessageSource resourceBundleMessageSource;

    public static String getMessage(String errorCode, Object... args) {
        if (resourceBundleMessageSource == null) {
            resourceBundleMessageSource = ApplicationContextHolder.getBean(ReloadableResourceBundleMessageSource.class);
        }
        String message = resourceBundleMessageSource.getMessage(errorCode, args, Locale.getDefault());
        if (StringUtils.isBlank(message)) {
            message = "message 未配置";
        }
        return message;
    }
}
